#include <thread>

#define N 100000000

long sum = 0;

void Tsum() {
  for (int i = 0; i < N; i++) {
    asm volatile("lock addq $1, %0": "+m"(sum));
  }
}

int main() {
  std::thread t1(Tsum);
  std::thread t2(Tsum);
  t1.join();
  t2.join();
  printf("sum = %ld\n", sum);
}